﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Users.WebSite.Register
{
	public partial class Index : PageBase
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			if (SiteConfig.RegisterMethod != RegisterMethod.Normal)
			{
				Response.Redirect("RegisterByEmail.aspx");
			}
		}

		/// <summary>
		/// 注册按钮触发
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		protected void BtnOK_Click(object sender, EventArgs e)
		{
			string username = this.TbUsername.Text.Trim();
			string password = this.TbPassword.Text.Trim();
			string confirmPassword = this.TbConfirmPassword.Text.Trim();

			if (!Utility.ValidateUsernameFormat(username))
			{
				this.Result.Failure("用户名不合法");
				return;
			}

			if (password != confirmPassword)
			{
				this.Result.Failure("两次输入的密码不一致");
				return;
			}

			if (!Utility.ValidatePasswordFormat(password))
			{
				this.Result.Failure("密码不合法");
				return;
			}

			UsersSf.UserService.CreateUser(username, password);

			// 作为注册完成标识，在RegisterComplete.aspx页面中使用
			Session["RegisterCompleteAccount"] = username;
			Response.Redirect("RegisterComplete.aspx");
		}
	}
}